﻿using System;
using System.Collections.Generic;
using System.Text;
using Components;

namespace UI.Lib
{
    public class ResultHelper
    {
        private bool _isSuccess = false;
        private Dictionary<string, object> _dict;

        public ResultHelper(string msg)
        {
            Msg = msg;

            if (string.IsNullOrEmpty(msg) == false)
            {
                try
                {
                    _dict = Json.ToObject<Dictionary<string, object>>(msg);

                    if (_dict != null)
                    {
                        if (_dict.ContainsKey("status"))
                            _isSuccess = Validation.ToBool(_dict["status"]);

                        if (_dict.ContainsKey("msg"))
                            Msg = Validation.ToString(_dict["msg"]);
                    }
                }
                catch
                {
                    ;
                }
            }
            else
            {
                _isSuccess = true;
            }
        }

        public static ResultHelper Parse(string msg)
        {
            return new ResultHelper(msg);
        }

        public Dictionary<string, object> ReturnObject
        {
            get { return _dict; }
        }

        public bool IsSuccess
        {
            get { return _isSuccess; }
            set { _isSuccess = value; }
        }

        public string Msg { get; set; }
    }
}
